#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
class Solution {
public:

    bool IsPopOrder(vector<int>& pushV, vector<int>& popV) {
        int n = pushV.size();
        stack<int> st;
        int j = 0;
        for (int i = 0; i < n; i++)
        {
            while (j < n && (st.empty() || st.top() != popV[i]))
                st.push(pushV[j++]);
            if (st.top() == popV[i])
                st.pop();
            else
                return false;
        }
        return true;
    }
};
int main()
{
    vector<int> push;
    push.push_back(1);
    push.push_back(2);
    push.push_back(3);
    push.push_back(4);
    push.push_back(5);
    vector<int> pop;
    pop.push_back(4);
    pop.push_back(5);
    pop.push_back(3);
    pop.push_back(2);
    pop.push_back(1);
    Solution().IsPopOrder(push, pop);
	return 0;
}